home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form Form1
- Caption = "Mabry News"
- ClientHeight = 8025
- ClientLeft = 1560
- ClientTop = 1905
- ClientWidth = 9990
- Height = 8715
- Left = 1500
- LinkTopic = "Form1"
- LockControls = -1 'True
- ScaleHeight = 535
- ScaleMode = 3 'Pixel
- ScaleWidth = 666
- Top = 1275
- Width = 10110
- Begin VB.CommandButton cmdCancelMsg
- Caption = "Cancel Msg"
- Height = 360
- Left = 6330
- TabIndex = 14
- Top = 135
- Width = 1035
- End
- Begin VB.CheckBox Flag
- Caption = "Flag"
- Height = 285
- Left = 9675
- TabIndex = 13
- Top = 240
- Visible = 0 'False
- Width = 750
- End
- Begin VB.CommandButton cmdReply
- Caption = "Reply"
- Height = 360
- Left = 5280
- TabIndex = 12
- Top = 135
- Width = 1050
- End
- Begin VB.CommandButton cmdNewArticle
- Caption = "New Article"
- Height = 360
- Left = 4230
- TabIndex = 11
- Top = 135
- Width = 1050
- End
- Begin VB.CheckBox Check2
- Caption = "Trace"
- Height = 195
- Left = 8520
- TabIndex = 10
- Top = 315
- Width = 795
- End
- Begin VB.CommandButton cmdVSplit
- Appearance = 0 'Flat
- BackColor = &H80000005&
- Height = 2880
- Left = 4395
- MousePointer = 9 'Size W E
- TabIndex = 9
- TabStop = 0 'False
- Top = 600
- Width = 90
- End
- Begin VB.CommandButton cmdHSplit
- BeginProperty Font
- name = "Arial"
- charset = 0
- weight = 400
- size = 1.5
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 90
- Left = 0
- MousePointer = 7 'Size N S
- TabIndex = 8
- Top = 3480
- Width = 9765
- End
- Begin VB.TextBox Text1
- BeginProperty Font
- name = "Courier New"
- charset = 0
- weight = 400
- size = 11.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 4230
- Left = 30
- Locked = -1 'True
- MultiLine = -1 'True
- ScrollBars = 3 'Both
- TabIndex = 7
- Top = 3570
- Width = 9690
- End
- Begin VB.ListBox listArticles
- Height = 2775
- IntegralHeight = 0 'False
- ItemData = "NEWS.frx":0000
- Left = 4440
- List = "NEWS.frx":0002
- TabIndex = 6
- Top = 660
- Width = 5235
- End
- Begin VB.CommandButton cmdGetNewGroups
- Caption = "New Groups"
- Height = 360
- Left = 2130
- TabIndex = 5
- Top = 135
- Width = 1050
- End
- Begin VB.ListBox listGroups
- Height = 2775
- IntegralHeight = 0 'False
- Left = 30
- TabIndex = 4
- Top = 660
- Width = 4335
- End
- Begin VB.CommandButton cmdGetAllGroups
- Caption = "All Groups"
- Height = 360
- Left = 3180
- TabIndex = 3
- Top = 135
- Width = 1050
- End
- Begin VB.CheckBox Check1
- Caption = "Blocking"
- Height = 195
- Left = 8520
- TabIndex = 2
- Top = 105
- Width = 960
- End
- Begin VB.CommandButton cmdDisconnect
- Caption = "Disconnect"
- Height = 360
- Left = 1080
- TabIndex = 1
- Top = 135
- Width = 1050
- End
- Begin VB.CommandButton cmdConnect
- Caption = "Connect"
- Height = 360
- Left = 30
- TabIndex = 0
- Top = 135
- Width = 1050
- End
- Begin NewsLib.News News1
- Left = 7560
- Top = 120
- _Version = 327680
- _ExtentX = 847
- _ExtentY = 847
- _StockProps = 0
- Debug = 1
- Blocking = -1 'True
- Timeout = 0
- End
- Begin VB.Line Line3
- BorderColor = &H00FFFFFF&
- X1 = 0
- X2 = 911
- Y1 = 0
- Y2 = 0
- End
- Begin VB.Line Line2
- BorderColor = &H00FFFFFF&
- X1 = -4
- X2 = 907
- Y1 = 39
- Y2 = 39
- End
- Begin VB.Line Line1
- BorderColor = &H00808080&
- X1 = 0
- X2 = 658
- Y1 = 38
- Y2 = 38
- End
- Begin VB.Menu FileMenu
- Caption = "&File"
- Begin VB.Menu FileExit
- Caption = "E&xit"
- End
- End
- Begin VB.Menu SettingsMenu
- Caption = "&Settings"
- Begin VB.Menu SettingsUser
- Caption = "&User..."
- End
- Begin VB.Menu SettingsConnection
- Caption = "&Connection..."
- End
- End
- Begin VB.Menu ShowMenu
- Caption = "Sh&ow"
- Begin VB.Menu ShowHeaders
- Caption = "&Headers"
- End
- End
- Attribute VB_Name = "Form1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- ' Sample program for Mabry News Control
- ' This sample shows both blocking and non-blocking use of
- ' the Mabry News control. Please note that this sample does
- ' not trap errors returned by the control (connection failure,
- ' for instance). If an error is returned you'll see the usual VB
- ' error message box.
- ' Zane Thomas/May 96
- Option Explicit
- ' state is used in non-blocking mode to determine what to do
- ' when the Done and DataReady events are fired
- Dim state As Integer
- Private Const StateDisconnected = 0
- Private Const StateGetGroups = 1
- Private Const StateSelectGroup = 2
- Private Const StateGetArticleIDs = 3
- Private Const StateGetArticle = 4
- Private Const StateGetHeader = 5
- Private Const StateXOver = 6
- Const StateConnecting = 7
- Const StateConnected = 8
- Const StateDisconnecting = 9
- ' For spacing during Form_Resize
- Private Const Margin = 2
- ' Used during article and group retrieval, see AddArticleIDsToList
- ' and Add GroupsToList for details
- Dim articleIndex As Integer
- Dim groupIndex As Integer
- ' Properties accessed by setup forms
- Private m_emailaddr As String
- Private m_logonname As String
- Private m_logonpass As String
- Public Property Let EmailAddr(s As String)
- m_emailaddr = s
- End Property
- Public Property Get EmailAddr() As String
- EmailAddr = m_emailaddr
- End Property
- Public Property Let LogonName(s As String)
- m_logonname = s
- End Property
- Public Property Get LogonName() As String
- LogonName = m_logonname
- End Property
- Public Property Let LogonPass(s As String)
- m_logonpass = s
- End Property
- Public Property Get LogonPass() As String
- LogonPass = m_logonpass
- End Property
- '''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Command Buttons
- '''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub cmdConnect_Click()
- News1.LogonName = Me.LogonName
- News1.LogonPassword = Me.LogonPass
- listGroups.Clear
- listArticles.Clear
- Text1.Text = ""
- If (Check1.Value = 1) Then
- News1.Blocking = True
- Else
- News1.Blocking = False
- End If
- EnableControls False
- state = StateConnecting
- News1.Action = NewsConnect
- If (News1.Blocking) Then
- News1_Done 0
- End If
- End Sub
- Private Sub cmdDisconnect_Click()
- EnableControls False
- state = StateDisconnecting
- News1.Action = NewsDisconnect
- listGroups.Clear
- listArticles.Clear
- Text1.Text = ""
- If (News1.Blocking) Then
- News1_Done 0
- End If
- End Sub
- Private Sub cmdGetAllGroups_Click()
- Dim i As Integer
- state = StateGetGroups
- EnableControls False
- listGroups.Clear
- groupIndex = 0
- News1.Action = NewsGetAllGroups
- If (News1.Blocking) Then
- News1_Done 0
- End If
- End Sub
- Private Sub cmdGetNewGroups_Click()
- state = StateGetGroups
- '
- ' A real newsreader would keep track of the last
- ' time the news groups were updated and supply an
- ' appropriate date here
- '
- News1.Date = Format("04/30/1996 00:00:00", "ddd, dd mmm yyyy hh:mm:ss")
- EnableControls False
- listGroups.Clear
- groupIndex = 0
- News1.Action = NewsGetNewGroups
- If (News1.Blocking) Then
- News1_Done 0
- End If
- End Sub
- Private Sub cmdNewArticle_Click()
- PostArticle False
- End Sub
- Private Sub cmdReply_Click()
- PostArticle True
- End Sub
- Sub PostArticle(reply As Boolean)
- Dim i As Integer
- Dim j As Integer
- Dim s As String
- Dim body As String
- '
- ' Set user info from e-mail address
- '
- i = InStr(m_emailaddr, "@")
- j = InStr(m_emailaddr, "(") - 1
- News1.EMailAddress = m_emailaddr
- News1.PostingHost = Mid(m_emailaddr, i + 1, j - i - 1)
- '
- ' Add optional headers
- '
- News1.HeadersCount = 0
- News1.Headers(0) = "Organization: Mabry Software http://www.mabry.com"
- News1.Headers(1) = "X-Newsreader: Mabry News"
- News1.Headers(2) = "X-Test: foo"
- '
- ' If this is a reply message
- '
- If (reply) Then
- '
- ' Set references line
- '
- s = News1.References & " " & News1.ArticleID
- Do While (Len(s) > 512)
- i = InStr(s, "> <")
- If (i = 0) Then
- ' This should never happen ... but
- Exit Do
- End If
- s = Right(s, Len(s) - (i + 1))
- Loop
- News1.References = s
- '
- ' Set groups and subject
- '
- NewMessage.NewsGroups.Text = News1.NewsGroups
- If (StrConv(Left(News1.Subject, 3), vbLowerCase) <> "re:") Then
- NewMessage.Subject.Text = "Re: " & News1.Subject
- Else
- NewMessage.Subject.Text = News1.Subject
- End If
- '
- ' Quote body text in reply
- '
- s = News1.BodyText
- body = News1.From & " wrote:" & vbCrLf
- Do While (s <> "")
- body = body & ">" & Left(s, InStr(s, Chr(13)) + 1)
- s = Right(s, Len(s) - (InStr(s, Chr(13)) + 1))
- Loop
- NewMessage.body.Text = body
- Else
- '
- ' New message
- '
- NewMessage.NewsGroups.Text = News1.group
- NewMessage.Subject.Text = ""
- News1.References = ""
- End If
- Flag.Value = 0
- NewMessage.Show 1
- If (Flag.Value = 0) Then
- Exit Sub
- End If
- News1.ArticleID = Format(Now(), "ddmmyyhhmmss") & "@" & News1.PostingHost
- News1.Date = Format(Now(), "ddd, dd mmm yyyy hh:mm:ss ") & "-0700"
- News1.PostArticle
- End Sub
- Private Sub cmdCancelMsg_Click()
- Dim i As Integer
- Dim j As Integer
- i = InStr(m_emailaddr, "@")
- j = InStr(m_emailaddr, "(") - 1
- News1.EMailAddress = m_emailaddr
- News1.PostingHost = Mid(m_emailaddr, i + 1, j - i - 1)
- News1.HeadersCount = 0
- News1.Subject = "cmsg cancel " & News1.ArticleID
- News1.NewsGroups = News1.NewsGroups & ",control.cancel"
- News1.Headers(0) = "Control: cancel " & News1.ArticleID
- News1.ArticleID = Format(Now(), "ddmmyyhhmmss") & "@" & News1.PostingHost
- News1.Date = Format(Now(), "ddd, dd mmm yyyy hh:mm:ss ") & "-0700"
- News1.References = ""
- News1.BodyText = ""
- News1.PostArticle
- End Sub
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' News Control Events
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub News1_AsyncError(ByVal ErrorCode As Long, ByVal Description As String)
- MsgBox "AsyncError: " & Description
- EnableControls True
- End Sub
- Private Sub News1_DataReady()
- Select Case state
- Case StateGetGroups
- AddGroupsToList groupIndex
- End Select
- End Sub
- Private Sub News1_Debug(ByVal Text As String)
- If (Check2.Value <> 0) Then
- Debug.Print Text
- End If
- End Sub
- Private Sub News1_Done(ByVal ErrorCode As Integer)
- Dim i As Integer
- Select Case state
- Case StateConnecting
- If (ErrorCode = 0) Then
- state = StateConnected
- End If
- EnableControls True
- Case StateDisconnecting
- state = StateDisconnected
- EnableControls True
- Case StateGetArticleIDs
- state = StateConnected
- articleIndex = 0
- ListHeaders
- Case StateGetGroups
- AddGroupsToList groupIndex
- state = StateConnected
- EnableControls True
- Case StateSelectGroup
- '
- ' Just finished selecting a group, get the article ids
- '
- ' Use this code if the xover command isn't
- ' supported for the connected server
- ' state = StateGetArticleIDs
- ' listArticles.Clear
- ' News1.Date = Format("05/22/1996 12:00:00", "ddd, dd mmm yyyy hh:mm:ss")
- ' articleIndex = 0
- ' News1.GetNewNews
- Flag.Value = 0
-
- msgrange.First.Text = News1.FirstArticle
- msgrange.Last.Text = News1.LastArticle
- msgrange.Show 1
- If (Flag.Value = 0) Then
- state = StateConnected
- EnableControls True
- Exit Sub
- End If
- ''''''''''''''''''''''
- ' cut this code for non-xover servers
- state = StateXOver
- News1.Action = NewsXover
- ' end cut
- ''''''''''''''''''''''
- If (News1.Blocking) Then
- ListHeaders
- state = StateConnected
- EnableControls True
- End If
- Case StateGetArticle
- state = StateConnected
- EnableControls True
- If (ShowHeaders.Checked) Then
- Text1.Text = News1.HeaderText & Chr$(13) & Chr$(10) & News1.BodyText
- Else
- Text1.Text = News1.BodyText
- End If
- Case StateGetHeader
- listArticles.AddItem News1.Subject
- ListHeaders
- Case StateXOver
- ListHeaders
- state = StateConnected
- EnableControls True
- Case Else
- state = StateConnected
- EnableControls True
- End Select
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Form
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub FileExit_Click()
- End
- End Sub
- Private Sub Form_Load()
- state = StateDisconnected
- EnableControls True
- News1.Host = "msnews.microsoft.com"
- News1.LogonName = ""
- News1.LogonPassword = ""
- Me.Show
- SetPopupPos UserInfo
- UserInfo.Show 1
- End Sub
- Private Sub Form_Resize()
- Line1.X2 = Me.ScaleWidth
- Line2.X2 = Me.ScaleWidth
- Line3.X2 = Me.ScaleWidth
- cmdVSplit.Height = cmdHSplit.Top - Line2.Y2 - 1
- cmdHSplit.Width = Me.ScaleWidth
- listGroups.Top = Line2.Y1 + Margin
- listGroups.Height = cmdHSplit.Top - Line2.Y1 - Margin * 2
- listGroups.Left = Margin
- listGroups.Width = cmdVSplit.Left - Margin * 2
- listArticles.Top = Line2.Y1 + Margin
- listArticles.Height = cmdHSplit.Top - Line2.Y1 - Margin * 2
- listArticles.Left = cmdVSplit.Left + cmdVSplit.Width + Margin
- listArticles.Width = Me.ScaleWidth - listArticles.Left - Margin
- Text1.Top = cmdHSplit.Top + cmdHSplit.Height + Margin
- Text1.Height = Me.ScaleHeight - (cmdHSplit.Top + cmdHSplit.Height) - Margin * 2
- Text1.Left = Margin
- Text1.Width = Me.ScaleWidth - Margin * 2
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Menus
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub SettingsConnection_Click()
- SetPopupPos ConnectionOptionsForm
- ConnectionOptionsForm.Show 1
- End Sub
- Private Sub SettingsUser_Click()
- SetPopupPos UserInfo
- UserInfo.Show 1
- End Sub
- Private Sub ShowHeaders_Click()
- ShowHeaders.Checked = Not ShowHeaders.Checked
- If (ShowHeaders.Checked) Then
- Text1.Text = News1.HeaderText & Chr$(13) & Chr$(10) & News1.BodyText
- Else
- Text1.Text = News1.BodyText
- End If
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' List Boxes
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub listGroups_DblClick()
- News1.group = listGroups.List(listGroups.ListIndex)
- News1.NewsGroups = News1.group
- state = StateSelectGroup
- EnableControls False
- News1.SelectGroup
- listArticles.Clear
- If (News1.Blocking) Then
- News1_Done 0
- End If
- End Sub
- Private Sub listArticles_DblClick()
- ' Use this code for non-xover servers
- ' News1.ArticleID = News1.ArticleIDs(listArticles.ListIndex)
- ' cut here for non-xover servers
- News1.ArticleID = listArticles.ItemData(listArticles.ListIndex)
- ' end cut
- state = StateGetArticle
- EnableControls False
- News1.GetArticle
- If (News1.Blocking) Then
- News1_Done 0
- End If
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Splitters
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub cmdHSplit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Dim oldy As Integer
- Dim newy As Integer
- Y = Y / Screen.TwipsPerPixelY
- oldy = cmdHSplit.Top
- newy = Y + cmdHSplit.Top - (cmdHSplit.Height / 2)
- If (newy = oldy) Then
- Exit Sub
- End If
- If (Button) Then
- cmdHSplit.Top = newy
- listGroups.Height = cmdHSplit.Top - listGroups.Top - Margin
- listArticles.Height = listGroups.Height
- Text1.Top = cmdHSplit.Top + cmdHSplit.Height + Margin
- Text1.Height = Me.ScaleHeight - (cmdHSplit.Top + cmdHSplit.Height) - Margin * 2
- cmdVSplit.Height = cmdHSplit.Top - Line2.Y2 - 1
- End If
- End Sub
- Private Sub cmdHSplit_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- If (listGroups.Enabled) Then
- listGroups.SetFocus
- End If
- End Sub
- Private Sub cmdVSplit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Dim oldx As Integer
- Dim newx As Integer
- X = X / Screen.TwipsPerPixelX
- oldx = cmdVSplit.Left
- newx = X + cmdVSplit.Left - (cmdVSplit.Width / 2)
- If (newx = oldx) Then
- Exit Sub
- End If
- If (Button) Then
- cmdVSplit.Left = newx
- listGroups.Width = cmdVSplit.Left - listGroups.Left - Margin
- listArticles.Left = cmdVSplit.Left + Margin + cmdVSplit.Width
- listArticles.Width = Me.ScaleWidth - listArticles.Left - 2 * Margin
- End If
- End Sub
- Private Sub cmdVSplit_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- If (listGroups.Enabled) Then
- listGroups.SetFocus
- End If
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Misc Subs
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Private Sub EnableControls(fEnable As Boolean)
- If (fEnable = False) Then
- cmdConnect.Enabled = fEnable
- cmdDisconnect.Enabled = fEnable
- cmdGetAllGroups.Enabled = fEnable
- cmdGetNewGroups.Enabled = fEnable
- cmdNewArticle.Enabled = fEnable
- cmdReply.Enabled = fEnable
- cmdCancelMsg.Enabled = fEnable
- listGroups.Enabled = fEnable
- listArticles.Enabled = fEnable
- ElseIf (state = StateConnected) Then
- cmdConnect.Enabled = False
- cmdDisconnect.Enabled = True
- cmdGetAllGroups.Enabled = True
- cmdGetNewGroups.Enabled = True
- cmdNewArticle.Enabled = True
- cmdReply.Enabled = True
- cmdCancelMsg.Enabled = True
- If (listGroups.ListCount > 0) Then
- listGroups.Enabled = True
- Else
- listGroups.Enabled = False
- End If
- If (listArticles.ListCount > 0) Then
- listArticles.Enabled = True
- Else
- listArticles.Enabled = False
- End If
- Else
- cmdConnect.Enabled = True
- cmdDisconnect.Enabled = False
- cmdGetAllGroups.Enabled = False
- cmdGetNewGroups.Enabled = False
- cmdNewArticle.Enabled = False
- cmdReply.Enabled = False
- cmdCancelMsg.Enabled = False
- listGroups.Enabled = False
- listArticles.Enabled = False
- End If
- End Sub
- Sub AddGroupsToList(i As Integer)
- Dim group As String
- Do While (i < News1.GroupCount)
- group = News1.Groups(i)
- group = Left$(group, InStr(group, " ") - 1)
- listGroups.AddItem group
- i = i + 1
- Loop
- End Sub
- Sub ListHeaders()
- '''''''''''''''''
- ' cut here for non-xover servers
- Dim i As Integer
- Dim s As String
- Dim n As Long
- For i = 0 To News1.XOverHeadersCount - 1
- s = News1.XOverHeaders(i)
- n = Val(Left(s, InStr(s, Chr(9)) - 1))
- s = Right(s, Len(s) - InStr(s, Chr(9)))
- s = Left(s, InStr(s, Chr(9)))
- listArticles.AddItem s
- listArticles.ItemData(i) = n
- Next
- ' end cut
- '''''''''''''''''
- ' Use this code for non-xover servers
- ' Note: Getting individual headers is a whole lot slower than using
- ' xover.
- ' If (News1.Blocking) Then
- ' Do While articleIndex < News1.ArticleIDsCount
- ' News1.ArticleID = News1.ArticleIDs(articleIndex)
- ' News1.GetHeader
- ' listArticles.AddItem News1.Subject
- ' articleIndex = articleIndex + 1
- ' DoEvents
- ' Loop
- ' Else
- ' If (articleIndex < News1.ArticleIDsCount) Then
- ' News1.ArticleID = News1.ArticleIDs(articleIndex)
- ' articleIndex = articleIndex + 1
- ' state = StateGetHeader
- ' News1.GetHeader
- ' Else
- ' EnableControls True
- ' state = StateNone
- ' End If
- ' End If
- End Sub
- Sub SetPopupPos(foo As Form)
- foo.Top = Me.Top + Me.Height / 5
- foo.Left = Me.Left + (Me.Width - foo.Width) / 2
- End Sub
-